package org.trackcore.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.trackcore.handler.DataHandler;
import org.trackcore.model.entity.BehaviorClick;
import org.trackcore.service.BehaviorClickService;
import org.trackcore.utils.DataUtils;

import java.util.Map;

@Service
public class BehaviorClickHandler implements DataHandler {
    private final BehaviorClickService behaviorClickService;

    public BehaviorClickHandler(BehaviorClickService behaviorClickService) {
        this.behaviorClickService = behaviorClickService;
    }
    @Override
    public String getHandlerKey() {
        return "behavior_click";
    }

    @Override
    public void handle(Map<String, Object> data, String logId) {
        BehaviorClick entity = BehaviorClick.builder()
                .logId(logId)
                .StarTime(DataUtils.getDouble(data, "StarTime"))
                .eventType(DataUtils.getString(data, "eventType"))
                .target(DataUtils.getString(data, "target"))
                .height(DataUtils.getInt(data, "height"))
                .innerHtml(DataUtils.getString(data, "innerHtml"))
                .outerHtml(DataUtils.getString(data, "outer"))
                .subType(DataUtils.getString(data, "subType"))
                .type(DataUtils.getString(data, "type"))
                .width(DataUtils.getInt(data, "width"))
                .pageUrl(DataUtils.getString(data, "pageUrl"))
                .build();
        behaviorClickService.save(entity);
    }
}
